<!--View/Elements/Accounts/index.ctp-->
<div id="transaction-list">
	<input type="hidden" id="base_date" value="<?php echo $base_date; ?>"/>
	<input type="hidden" id="from_date" value="<?php echo $from; ?>"/>
	<input type="hidden" id="to_date" value="<?php echo $to; ?>"/>
	<div class="row row-margin-20">
		<div class="col-md-1 col-md-offset-3">
			<button class="btn btn-default pull-left navigator prev">< Trước</button>
		</div>
		<div class="col-md-4" style="text-align: center">
			<span class="list-title">
				<?php
				if ('week' == $view_mode) {
					echo date('d/m/Y', strtotime($from));
					echo ' - ';
					echo date('d/m/Y', strtotime($to));
				} else {
					echo 'Tháng ' . date('m/Y', strtotime($base_date));
				}
				?>
			</span>
		</div>
		<div class="col-md-1">
			<button class="btn btn-default pull-right navigator next">Tiếp ></button>
		</div>
	</div>
	<div class="row row-margin-20">
		<div class="col-md-6 col-md-offset-3">
			<?php
				if(0 === count($transactions)) {
					echo  '<p style="text-align:center;">Không có dữ liệu.</p>';
				}
			?>
			<table class="table table-bordered table-condensed table-striped table-hover">
				<?php $date = ""; ?>
				<?php foreach ($transactions as $item): ?>
					<?php
					$mydate = strtotime($item['Transaction']['date']);
					$mydate = date('d/m/Y', $mydate);
					if ($date != $mydate) {
						$date = $mydate;
						//Display date row
						echo '<tr class="success date-title"><td>' . $date . '</td></tr>';
					}
					?>
					<tr>
						<td>
							<?php
							$icon_name = empty($item['Category']['icon_path']) ? 'Question-icon.png' : $item['Category']['icon_path'];
							echo $this->Html->image('icons/categories/' . $icon_name, array('class' => 'icon'));
							echo $item['Transaction']['name'];
							echo '<span';
							echo ' class="pull-right label label-md label-' . AppConstants::$transaction_type_bootstrap_colors[$item['Transaction']['type']] . '">';
							echo $item['Transaction']['amount'];
							echo '</span>';
							?>
						</td>
					</tr>
				<?php endforeach; ?>
			</table>
		</div>
	</div>
</div>
<script>
	$(function() {
		$("#transaction-list .navigator").click(function() {
			var modifier = "0";
			if ($(this).hasClass("prev")) {
				modifier = "-1";
			} else if ($(this).hasClass("next")) {
				modifier = "+1";
			}
			var base_date = $("input#base_date").val();
			load_transaction_element("#transaction_element", base_date, modifier, null);
		});
	});
</script>
<?php $this->Js->writeBuffer(); ?>